package com.yiji.fintech.musfinance.common.enginerules.rules;

import com.acooly.core.utils.Money;
import com.yiji.fintech.musfinance.common.annotation.RuleNameAnnotation;
import com.yiji.fintech.musfinance.common.enginerules.base.RulesFilter;
import com.yiji.fintech.musfinance.common.domain.channel.ChannelDomain;
import com.yiji.fintech.musfinance.common.domain.channel.InstChannelApiDomain;
import org.springframework.stereotype.Service;

import java.util.Iterator;

/**
 * 渠道金额业务限额规则(指定金额范围渠道)
 * Created by ouwen@yiji.com} on 2017/9/22.
 */
@Service
@RuleNameAnnotation("业务限额规则服务")
public class BizQuotaRuleService extends RulesFilter {
    @Override
    public void filter(ChannelDomain domain) {
        Iterator<InstChannelApiDomain> iterator = channelApiList.iterator();
        while (iterator.hasNext()) {
            Money amount = domain.getAmount();//交易金额
            InstChannelApiDomain channelRule = iterator.next();
            Money ruleAmount = channelRule.getRuleAmount();
            if(ruleAmount == null) {
                continue;
            }
            switch (channelRule.getCalculateType()) {
                case GREATERTHAN://大于
                    if (amount.compareTo(ruleAmount) > 0) {
                    } else {
                        iterator.remove();
                    }
                    break;
                case GREATERTHANEQULES://大于等于
                    if (amount.compareTo(ruleAmount) >= 0) {
                    } else {
                        iterator.remove();
                    }
                    break;
                case EQULES:
                    if (amount.compareTo(ruleAmount) == 0) {
                    } else {
                        iterator.remove();
                    }
                    break;
                case LESSTHAN://小于
                    if (amount.compareTo(ruleAmount) < 0) {
                    } else {
                        iterator.remove();
                    }
                    break;
                case LESSTHANEQULES://小于等于
                    if (amount.compareTo(ruleAmount) <= 0) {
                    } else {
                        iterator.remove();
                    }
                    break;
                case UNLIMITED://无限制

                    break;
            }
        }
    }
}
